package com.diapoc.androidteacher.listview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.diapoc.androidteacher.R;

public class Activity_ListView_SimpleAdapter extends Activity {

	private Context context;
	private String tag;

	Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
		}
	};

	private void init() {
		context = this;
		tag = this.getLocalClassName();
		initLayout();
	}

	private void initLayout() {
		ListView lv = new ListView(context);
		SimpleAdapter adapter = new SimpleAdapter(this, getData(),
				R.layout.listview_simpleadapter_item, new String[] { "title",
						"img" }, new int[] { R.id.title, R.id.img });
		lv.setAdapter(adapter);
		setContentView(lv);
	}

	private List<Map<String, Object>> getData() {
		// map.put(参数名字,参数值)
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();

		for (int i = 0; i < 20; i++) {
			map = new HashMap<String, Object>();
			map.put("title", "SimpleAdapter_" + i);
			map.put("img", R.drawable.ic_launcher);
			list.add(map);
		}

		return list;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.v(tag, "onCreate");
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.activity_main);
		init();
	}

	public void onStart() {
		Log.v(tag, "onStart");
		super.onStart();
	}

	public void onResume() {
		Log.v(tag, "onResume");
		super.onResume();
	}

	public void onPause() {
		Log.v(tag, "onPause");
		super.onPause();
	}

	public void onStop() {
		Log.v(tag, "onStop");
		super.onStop();
	}

	public void onDestroy() {
		Log.v(tag, "onDestroy");
		super.onDestroy();
	}

}
